export {}

// 属性必须进行赋值
class Person {
  name: string;
  private age: number = 27;
  protected gender: boolean;

  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
    this.gender = true;
  }

  sayHi (msg: string): string {
    return `I am ${this.name}, ${this.age}`;
  }
}

class Student extends Person {
  private constructor(name: string, age: number) {
    super(name, age);
    console.log(this.gender); // 可以访问到
  }

  static create (name: string, age: number) {
    return new Student(name, age);
  }
}

const tom = new Person('tom', 18);
console.log(tom.name);
// console.log(tom.age); // 报错
// console.log(tom.gender); // 报错

// const bob = new Student('bob', 20); // 报错,因为constructor是private的
const jack = Student.create('jack', 18);